// Copyright Notice:
//				calendar.js v1.0.2
//			Copyright@2008 - OpenSiteMobile
//				All rights reserved
// ==========================================================================
//			http://www.opensitemobile.com
// ==========================================================================
// Contact Information:
//			Author: Dwight Vietzke
//			Email:  dwight_vietzke@yahoo.com

/*
	OpenSiteMobile calendar w/dojo integration
*/

dojo.provide("msos.calendar");
dojo.require("msos.common");
dojo.require("dojo.date.locale");
dojo.require("dojo.cldr.supplemental");
dojo.require("dojo.dnd.Moveable");
dojo.require("dojo.i18n");


msos.calendar.generate_tool = function(input_elm, window_elm, config) {

	// Get the language file to use as base
	dojo.requireLocalization('msos', 'calendar', djConfig.locale);
	var i18n_obj = dojo.i18n.getLocalization('msos', 'calendar', djConfig.locale);

	// Set the current date
	var current = new Date();
	this.curr_date = current.getDate();
	this.curr_mon  = current.getMonth();
	this.curr_year = current.getFullYear();
	this.cal_date  = null;
	this.cal_year  = null;
	this.cal_month = null;
	this.cal_inp_elm = input_elm;
	this.cal_window  = window_elm;
	this.cal_lang	 = i18n_obj;
	this.cal_cfg	 = config;
	this.focus_value = '';
	this.suppressed_elements = new Array();
	// Default 'on completion' function
	this.on_complete_func = function() { alert(i18n_obj.input_complete); }

	// Generate day, month name arrays
	this.mon_name = dojo.date.locale.getNames('months','wide',  'standAlone', djConfig.locale);
	this.long_day = dojo.date.locale.getNames('days',  'wide',  'standAlone', djConfig.locale);
	this.shrt_day = dojo.date.locale.getNames('days',  'narrow','standAlone', djConfig.locale);
	this.abbr_day = dojo.date.locale.getNames('days',  'abbr',  'standAlone', djConfig.locale);
	this.first_dow= dojo.cldr.supplemental.getFirstDayOfWeek(djConfig.locale);

	this.example_date = function() {
		var example = dojo.date.locale.format(new Date(), config.std_in_out_date_format);

		for (var k = 0; k < config.alt_input_date_formats.length; k++) {
			example += ' | ' + dojo.date.locale.format(new Date(), config.alt_input_date_formats[k]);
		}
		return example;
	};

	this.generate_date = function(year, mon, day) {
		return dojo.date.locale.format(new Date(year, mon, day), config.std_in_out_date_format);
	};

	// --------------------------
	// Event Functions
	// --------------------------

	// Make our calendar object avail to event functions
	var cal_object = this;

	this.cal_button_onmouseup = function() {
		// If already open, close it
		if(window_elm.style.visibility == 'visible') {
			cal_object.hide_cal_window();
			input_elm.focus();
			return false;
		}
		// If input date can't be read, set focus and select it
		if (!cal_object.get_input_date(input_elm.value)) {
			input_elm.focus();
			input_elm.select();
			return false;
		}
		cal_object.create_cal_window(cal_object.cal_year, cal_object.cal_month);
		return true;
	}

	this.input_ondblclick = function() {
		// If input date can't be read, set focus and select it
		if (!cal_object.get_input_date(input_elm.value)) {
			input_elm.focus();
			input_elm.select();
			return false;
		}
		cal_object.create_cal_window(cal_object.cal_year, cal_object.cal_month);
		return true;
	}

	this.body_onclick = function(evt) {
		if (!evt.target.id.match(/drag_calendar|calendar_window|cal_footer/)) cal_object.hide_cal_window();
		msos.common.event_debug(evt, "\nCalendar body - onclick");
	}

	this.input_onfocus = function(evt) {
		cal_object.focus_value = input_elm.value;
		msos.common.event_debug(evt, "\nCalendar input - onfocus");
	}

	this.input_onblur = function(evt) {
		msos.common.event_debug(evt, "\nCalendar input - onblur");
		if(input_elm.value != cal_object.focus_value) {
			if (!cal_object.get_input_date(input_elm.value)) {
				// focus() must be delayed to work in Netscape, Mozilla
				setTimeout(cal_object.onblur_delay, 100);
				return false;
			}
			// Value changed but checked out ok, so execute our on complete function
			if(cal_object.cal_cfg.exec_on_complete) cal_object.on_complete_func();
		}
		return true;
	}

	this.onblur_delay = function() { input_elm.focus();  input_elm.select(); }

	// Add standard input element event actions
	dojo.connect(input_elm,	 "onfocus",	null, cal_object.input_onfocus	);
	dojo.connect(input_elm,	 "onblur",	null, cal_object.input_onblur	);
	dojo.connect(dojo.body(),"onclick",	null, cal_object.body_onclick	);
	dojo.connect(input_elm,	 "ondblclick",	null, cal_object.input_ondblclick);


	// --------------------------
	// Finish setting up our calendar
	// --------------------------

	// Add our input example title here...
	input_elm.title = this.cal_lang.input_format_msg + ' ' + cal_object.example_date();

	// Set the position of our calendar
	if (config.position_below) config.adj_top += input_elm.offsetHeight || 0;
	msos.common.set_popup_position(window_elm, input_elm, config);

	// Add drag functionality to calendar div
        new dojo.dnd.Moveable(window_elm);
}

// --------------------------
// Calendar Display Functions
// --------------------------

msos.calendar.generate_tool.prototype.hide_cal_window = function() {
	this.cal_window.style.visibility = 'hidden';
	this.cal_window.innerHTML = "";
	if (document.all) this.restore_ie_objects();
	this.cal_date	= null;
	this.cal_month	= null;
	this.cal_year	= null;
}

msos.calendar.generate_tool.prototype.display_cal_window = function() {
	if (document.all) this.suppress_ie_objects();
	this.cal_window.style.visibility = 'visible';
}

// --------------------------
// Calendar Creation Functions
// --------------------------

msos.calendar.generate_tool.prototype.create_cal_window = function(y, m) {
	// Clear html for prior/next month or year rebuild
	this.cal_window.innerHTML = "";
	console.debug('Create calendar: year -> ' + y + ', month -> ' + m);
	var cal_object = this;
	var start_day = this.first_dow;
	var start_month = new Date(y,m,1).getDay();
	var prior_month = m - 1;
	var next_month  = m + 1;
	var prior_year = y - 1;
	var next_year  = y + 1;
	var prior_month_year = y;
	var next_month_year  = y;
	// Adjust for + or - year
	if(prior_month == -1){ prior_month = 11;	prior_month_year--;	}
	if(next_month == 12) { next_month = 0;		next_month_year++;	}
	// Get last day of m-1, then generate month limits
	var pr_mon_obj = new Date(prior_month_year, prior_month, 1);
	var p_mon_last = dojo.date.getDaysInMonth(pr_mon_obj)
	var n_mon_limit = new Date(next_month_year,	next_month,  1		);
	var p_mon_limit = new Date(prior_month_year,	prior_month, p_mon_last	);
	// Get last day of y-1, then generate year limits
	var pr_year_obj = new Date(prior_year, m, 1);
	var p_yr_last = dojo.date.getDaysInMonth(pr_year_obj)
	var n_yr_limit = new Date(next_year,  m, 1		);
	var p_yr_limit = new Date(prior_year, m, p_yr_last	);
	var show_next_mon	= 'no';
	var show_prior_mon	= 'no';
	var show_next_year	= 'no';
	var show_prior_year	= 'no';
	if (!this.cal_cfg.cal_top_date
	|| ( this.cal_cfg.cal_top_date
	&&   this.cal_cfg.cal_top_date > n_mon_limit))	{ show_next_mon		= 'yes'; }
	if (!this.cal_cfg.cal_bot_date
	|| ( this.cal_cfg.cal_bot_date
	&&   this.cal_cfg.cal_bot_date < p_mon_limit))	{ show_prior_mon	= 'yes'; }
	if (show_next_mon == 'yes'
	&&  (this.cal_cfg.cal_top_date > n_yr_limit))	{ show_next_year 	= 'yes'; }
	if (show_prior_mon == 'yes'
	&&  (this.cal_cfg.cal_bot_date < p_yr_limit))	{ show_prior_year 	= 'yes'; }

	// Create our calendar's month display table...
	var mon_table			= document.createElement("table");
	    mon_table.className		= 'cal_table';
	var mon_table_body		= document.createElement("tbody");
	var mon_table_th_row		= document.createElement("tr");
	var mon_table_th		= document.createElement("th");

	var th_title = this.mon_name[m] + ' ' + y;

	if(this.cal_cfg.use_prior_next_links) {
		if (show_prior_year == 'yes') {
			var onclick_func = function(evt) {
				evt.preventDefault();
				evt.stopPropagation();
				cal_object.create_cal_window(prior_year, m);
			}
			var mon_ahref = document.createElement("a");
			mon_ahref.href = "javascript:void(0)";
			mon_ahref.title = '<- ' + prior_year;
			mon_ahref.innerHTML = this.cal_cfg.prior_month_text;
			dojo.connect(mon_ahref, "onclick", null, onclick_func);
			mon_table_th.appendChild(mon_ahref);
		} else {
			var mon_span = document.createElement("span");
			mon_span.innerHTML = this.cal_cfg.prior_next_na;
			mon_table_th.appendChild(mon_span);
		  }
		if (show_prior_mon == 'yes') {
			var pr_mon = this.mon_name[prior_month]
			var onclick_func = function(evt) {
				evt.preventDefault();
				evt.stopPropagation();
				cal_object.create_cal_window(prior_month_year, prior_month);
			}
			var mon_ahref = document.createElement("a");
			mon_ahref.href = "javascript:void(0)";
			mon_ahref.title = '<- ' + pr_mon;
			mon_ahref.innerHTML = this.cal_cfg.prior_month_text;
			dojo.connect(mon_ahref, "onclick", null, onclick_func);
			mon_table_th.appendChild(mon_ahref);
		} else {
			var mon_span = document.createElement("span");
			mon_span.innerHTML = this.cal_cfg.prior_next_na;
			mon_table_th.appendChild(mon_span);
		  }
		var mon_cent_span = document.createElement("span");
		mon_cent_span.innerHTML = '<span id="drag_calendar" title="' + this.cal_lang.calendar_position + '">' + th_title + '</span>';
		mon_table_th.appendChild(mon_cent_span);
		if (show_next_mon == 'yes') {
			var nt_mon = this.mon_name[next_month]
			var onclick_func = function(evt) {
				evt.preventDefault();
				evt.stopPropagation();
				cal_object.create_cal_window(next_month_year, next_month);
			}
			var mon_ahref = document.createElement("a");
			mon_ahref.href = "javascript:void(0)";
			mon_ahref.title = nt_mon + ' ->';
			mon_ahref.innerHTML = this.cal_cfg.next_month_text;
			dojo.connect(mon_ahref, "onclick", null, onclick_func);
			mon_table_th.appendChild(mon_ahref);
		} else {
			var mon_span = document.createElement("span");
			mon_span.innerHTML = this.cal_cfg.prior_next_na;
			mon_table_th.appendChild(mon_span);
		  }
		if (show_next_year == 'yes') {
			var onclick_func = function(evt) {
				evt.preventDefault();
				evt.stopPropagation();
				cal_object.create_cal_window(next_year, m);
			}
			var mon_ahref = document.createElement("a");
			mon_ahref.href = "javascript:void(0)";
			mon_ahref.title = next_year + ' ->';
			mon_ahref.innerHTML = this.cal_cfg.next_month_text;
			dojo.connect(mon_ahref, "onclick", null, onclick_func);
			mon_table_th.appendChild(mon_ahref);
		} else {
			var mon_span = document.createElement("span");
			mon_span.innerHTML = this.cal_cfg.prior_next_na;
			mon_table_th.appendChild(mon_span);
		  }
	} else {
		mon_table_th.innerHTML = th_title;
	  }

	// Add our month display <th>...
	mon_table_th_row.appendChild(mon_table_th);

	// Finish our month table...
	mon_table_body.appendChild(mon_table_th_row);
	mon_table.appendChild(mon_table_body);

	// Create our calendar's day display table...
	var day_table		= document.createElement("table");
	    day_table.className	= 'cal_table';
	var day_table_body	= document.createElement("tbody");
	var day_table_th_row	= document.createElement("tr");

	// Start calendar day header...
	for(var i=0; i<7; i++, start_day++) {
		if(start_day == 7) start_day = 0;
		var day_table_th = document.createElement("th");
		day_table_th.title = this.long_day[start_day];
		switch(this.cal_cfg.day_title_format) {
			case "shrt_day":
				day_table_th.innerHTML = this.shrt_day[start_day];
				break;
			case "abbr":
			default:
				day_table_th.innerHTML = this.abbr_day[start_day];
				break;
		}
		day_table_th_row.appendChild(day_table_th);
	}

	// Append the day <th> display row
	day_table_body.appendChild(day_table_th_row);

	// Generate the calendar rows...
	var column = 0;
	var row = 0;
	var calendar_rows = [];
	calendar_rows[row] = document.createElement("tr");	// 1st row

	start_month = start_month - this.first_dow;
	if(start_month < 0) start_month = 7 + start_month;

	// Add the days for the prior month...
	for(var i = 0; i < start_month; i++, column++) {
		var prior_mon_obj = new Date(prior_month_year, prior_month, 1);
		var p_mon_last = dojo.date.getDaysInMonth(prior_mon_obj);
		var prior_mon_td = this.calendar_td(prior_month_year, prior_month, (p_mon_last - start_month + i + 1), 'prior');
		calendar_rows[row].appendChild(prior_mon_td);
	}

	// Add the days for the current month...
	var curr_mon_obj = new Date(y, m, 1);
	var c_mon_last = dojo.date.getDaysInMonth(curr_mon_obj);
	for(var i = 1; i <= c_mon_last; i++, column++) {
		var curr_mon_td = this.calendar_td(y, m, i, 'curr');
		calendar_rows[row].appendChild(curr_mon_td); 
		if(column == 6) {
			if(i < c_mon_last){
				row++;
				column=-1;
				calendar_rows[row] = document.createElement("tr");	// add additional row
			}
		}
	}

	// Add the days for the next month...
	var j = 0;
	if (column > 0) {
		for (var j=1; column<7; j++, column++)	{
			var next_mon_td = this.calendar_td(next_month_year, next_month, j, 'next');
			calendar_rows[row].appendChild(next_mon_td);
		}
	}

	// Make the calendar with 6 rows each time?
	if(this.cal_cfg.use_six_rows) {
		for(y = row; y < 5; y++) {
			calendar_rows[++row] = document.createElement("tr");	// add another (forced) row
			for(var x=0; x < 7; x++, j++) {
				var last_mon_td = this.calendar_td(next_month_year, next_month, j, 'next');
				calendar_rows[row].appendChild(last_mon_td);
			}
		}
	}
	// Append just generated calendar <tr> rows...
	for(var k = 0; k < calendar_rows.length; k++) { day_table_body.appendChild(calendar_rows[k]); }

	// Finish our day display table...
	day_table.appendChild(day_table_body);

	var foot_div = document.createElement("div");
	foot_div.id = 'cal_footer';
	if(this.cal_cfg.use_today_date_link) {
		var onclick_func = function(evt) {
			evt.preventDefault();
			evt.stopPropagation();
			cal_object.enter_date(cal_object.curr_year, cal_object.curr_mon, cal_object.curr_date, cal_object.cal_cfg.close_cal_on_date_pick);
		}
		var today_ahref = document.createElement("a");
		today_ahref.innerHTML = this.cal_lang.today_link_text;
		today_ahref.href = "javascript:void(0)";
		today_ahref.title = this.cal_lang.today_link_title;
		dojo.connect(today_ahref, "onclick", null, onclick_func);
		foot_div.appendChild(today_ahref);
	}
	if(this.cal_cfg.use_no_date_link) {
		var onclick_func = function(evt) {
			evt.preventDefault();
			evt.stopPropagation();
			cal_object.enter_blank();
		}
		if(this.cal_cfg.use_today_date_link) {
			var no_date_txt_node = document.createTextNode('  ');
			foot_div.appendChild(no_date_txt_node);
		}
		var no_date_ahref = document.createElement("a");
		no_date_ahref.innerHTML = this.cal_lang.no_date_link_text;
		no_date_ahref.href = "javascript:void(0)";
		no_date_ahref.title = this.cal_lang.no_date_link_title;
		dojo.connect(no_date_ahref, "onclick", null, onclick_func);
		foot_div.appendChild(no_date_ahref);
	}

	// Append <table>'s and footer <div> into calendar div
	this.cal_window.appendChild(mon_table);
	this.cal_window.appendChild(day_table);
	this.cal_window.appendChild(foot_div);

	// Now display new calendar
	this.display_cal_window();
}

msos.calendar.generate_tool.prototype.calendar_td = function(y, m, d, type) {
	var cal_object = this;
	var td_date = new Date(y, m, d);
	var td_dow  = td_date.getDay();
	var td_out  = '';
	var td_style = [];
	var td_style_string = '';
	var td_week_day = (td_dow != 0 && td_dow != 6);
	var td_doy = dojo.date.locale._getDayOfYear(td_date);
	var td_woy = dojo.date.locale._getWeekOfYear(td_date, this.first_dow);
	var td_doy_txt = ", " + this.cal_lang.day_of_year_text  + " - " + td_doy;
	var td_woy_txt =	this.cal_lang.week_of_year_text + " - " + td_woy;
	var is_entered_date = ( this.cal_year == y && this.cal_month == m && this.cal_date  == d);
	var is_current_date = (this.curr_year == y && this.curr_mon  == m && this.curr_date == d);
	var td_no_date = this.generate_date(y, m, d);

	td_no_date += ' - ' + this.cal_lang.day_not_allowed_text;
	
	// Set the td style...
	if ((type == 'prior')
	 || (type == 'next'))		{ td_style.push('cal_prior');	}
	if (is_entered_date
	 && is_current_date)		{ td_style.push('cal_both');	}
	else if (is_entered_date)	{ td_style.push('cal_entered');	}
	else if (is_current_date)	{ td_style.push('cal_current');	}
	else {
		if (td_week_day)	{ td_style.push('cal_weekday');	}
		else			{ td_style.push('cal_weekend');	}
	}

	// Build the td output element...
	var avail_date = 'yes';
	var td_out = document.createElement("td");
	var td_click_func = function(evt) {
		evt.preventDefault();
		evt.stopPropagation();
		if (avail_date == 'yes')	cal_object.enter_date(y, m, d, cal_object.cal_cfg.close_cal_on_date_pick);
		else				alert(td_no_date);
	}
	dojo.connect(td_out, "onclick", null, td_click_func);

	if(type == 'curr'
	||(type == 'prior' && this.cal_cfg.display_prior_mon_days)
	||(type == 'next'  && this.cal_cfg.display_next_mon_days)) {
		if ( td_week_day && !this.cal_cfg.pick_weekdays)		avail_date = 'no';
		if (!td_week_day && !this.cal_cfg.pick_weekends)		avail_date = 'no';
		if (type == 'prior' && !this.cal_cfg.pick_prior_mon_days)	avail_date = 'no';
		if (type == 'next'  && !this.cal_cfg.pick_next_mon_days)	avail_date = 'no';
		if (this.cal_cfg.cal_top_date
		&&  this.cal_cfg.cal_top_date < td_date)			avail_date = 'no';
		if (this.cal_cfg.cal_bot_date
		&&  this.cal_cfg.cal_bot_date > td_date)			avail_date = 'no';

		if (avail_date == 'yes')	td_style.push('cal_available');
		else				td_style.push('cal_not_avail');

		td_style_string = td_style.join(" ");
		td_out.className = td_style_string;

		if (avail_date == 'yes')	{
			td_out.title = td_woy_txt + td_doy_txt;
			td_out.innerHTML = d;
		} else {
			td_out.title = td_no_date;
			td_out.innerHTML = d;
		  }
	} else {
		td_style.push('cal_not_avail');
		td_style_string = td_style.join(" ");
		td_out.className = td_style_string;
		if (is_current_date) {
			td_out.title = this.cal_lang.current_date;
			td_out.innerHTML = d;
		} else if (is_entered_date) {
			td_out.title = this.cal_lang.entered_date;
			td_out.innerHTML = d;
		} else {
			td_out.title = type;
			td_out.innerHTML = ' ';
		  }
	  }
	return td_out;
}

msos.calendar.generate_tool.prototype.enter_blank = function() {
	if(this.cal_inp_elm.value != this.cal_cfg.blank_date_text) {
		this.cal_inp_elm.value = this.cal_cfg.blank_date_text;
	}
	this.hide_cal_window();
}

msos.calendar.generate_tool.prototype.enter_date = function(y, m, d, hide) {
	this.cal_year  = y;
	this.cal_month = m;
	this.cal_date  = d;
	var old_date = this.cal_inp_elm.value;
	var new_date = this.generate_date(y, m, d);
	if(old_date != new_date) {
		console.debug("Enter date: " + new_date);
		this.cal_inp_elm.value = new_date;	
		if(this.cal_cfg.exec_on_complete && hide) this.on_complete_func();
	}
	if(hide) this.hide_cal_window();
}

msos.calendar.generate_tool.prototype.suppress_ie_objects = function() {
	// Suppress IE objects under present calendar window position
	msos.common.set_suppress_ie_objects(
		this.cal_window,
		this.cal_cfg.ie_element_suppression,
		this.suppressed_elements
	);
	for(i=0; i<this.suppressed_elements.length; i++) {
		this.suppressed_elements[i].style.visibility = 'hidden';
	}
}

msos.calendar.generate_tool.prototype.restore_ie_objects = function() {
	for(i=0; i<this.suppressed_elements.length; i++) {
		this.suppressed_elements[i].style.visibility = "";
	}
	this.suppressed_elements = [];
}

msos.calendar.generate_tool.prototype.get_input_date = function(input_date_strg) {
	if(!input_date_strg || input_date_strg == this.cal_cfg.blank_date_text) {
		if(this.cal_month == null || this.cal_year == null) {
			(this.cal_cfg.initial_date) ? this.cal_month = this.cal_cfg.initial_date.getMonth()	: this.cal_month = this.curr_mon;
			(this.cal_cfg.initial_date) ? this.cal_year  = this.cal_cfg.initial_date.getFullYear()	: this.cal_year  = this.curr_year;
		}
		return true;
	}
	input_date_strg = dojo.trim(input_date_strg);
	input_date_strg = input_date_strg.replace(/\s\s+/g, " ");
	// Try std localized 'date' selector first
	console.debug("get_input_date -> input value: " + input_date_strg);
	var input_date_obj = dojo.date.locale.parse(input_date_strg, this.cal_cfg.std_in_out_date_format) || null;
	// Now try some dojo typical alternate patterns
	if (!input_date_obj) {
		var dojo_array = this.cal_cfg.alt_input_date_formats;
		for (var k = 0; k < dojo_array.length; k++) { 
			input_date_obj = dojo.date.locale.parse(input_date_strg, dojo_array[k]) || null;
			if (input_date_obj) {
				console.debug('get_input_date -> dojo format: ' + dojo_array[k].formatLength);
				break;
			}
		}
		// Now try some language specific filter formats as a last attempt
		if (!input_date_obj && this.cal_cfg.lang_specific_date_formats[djConfig.locale]) {
			var filter_array = this.cal_cfg.lang_specific_date_formats[djConfig.locale];
			for (var l = 0; l < filter_array.length; l++) {
				input_date_obj = dojo.date.locale.parse(input_date_strg, filter_array[l]) || null;
				if (input_date_obj) {
					console.debug('get_input_date -> alt lang format: ' + filter_array[l].datePattern);
					break;
				}
			}
		}
		
	}
	if (!input_date_obj) {
		alert(this.cal_lang.input_format_msg + ' ' + this.example_date());
		return false;
	}
	var in_year = input_date_obj.getFullYear();
	var in_mon  = input_date_obj.getMonth();
	var in_date = input_date_obj.getDate();

	if(!isNaN(in_date) && !isNaN(in_mon) && !isNaN(in_year)) {
		var parsed_date = new Date(in_year, in_mon, in_date);
		if (this.cal_cfg.cal_top_date
		&&  this.cal_cfg.cal_top_date < parsed_date) {
			var formatted = dojo.date.locale.format(
				this.cal_cfg.cal_top_date,
				this.cal_cfg.std_in_out_date_format
			);
			alert(
			      this.cal_lang.date_allowable_text + ' ' +
			      this.cal_lang.top_allowable_text  + ' ' +
			      formatted
			);
			in_date = this.cal_cfg.cal_top_date.getDate();
			in_mon  = this.cal_cfg.cal_top_date.getMonth();
			in_year = this.cal_cfg.cal_top_date.getFullYear();
			this.enter_date(in_year, in_mon, in_date);
			return false;
		}
		if (this.cal_cfg.cal_bot_date
		&&  this.cal_cfg.cal_bot_date > parsed_date) {
			var formatted = dojo.date.locale.format(
				this.cal_cfg.cal_bot_date,
				this.cal_cfg.std_in_out_date_format
			);
			alert(
			      this.cal_lang.date_allowable_text + ' ' +
			      this.cal_lang.bot_allowable_text  + ' ' +
			      formatted
			);
			in_date = this.cal_cfg.cal_bot_date.getDate();
			in_mon  = this.cal_cfg.cal_bot_date.getMonth();
			in_year = this.cal_cfg.cal_bot_date.getFullYear();
			this.enter_date(in_year, in_mon, in_date);
			return false;
		}
		this.enter_date(in_year, in_mon, in_date);
		return true;
	} else {
		return false;
	  }
}